package com.action.service.pressenter;

import com.base.app_core.base.ActionPacketView;
import com.base.app_core.base.impl.BasePresenter;
import com.base.app_core.model.Paginated;
import com.base.app_core.model.PoiList;
import com.base.app_core.service.Retrofit.RestServer;
import com.base.app_core.service.rx.Callback;
import com.base.app_core.util.AppConstants;
import com.base.app_core.util.liteorm.DBHandleEvent;
import com.base.app_core.util.liteorm.MyIChatDBHelpUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

/**
 * Created by Administrator on 19/03/2018.
 */

public class SelectCurrentLocationPresenter extends BasePresenter<ActionPacketView.onPoiResult> {

    @Inject
    MyIChatDBHelpUtils myIChatDBHelpUtils;

    @Inject
    public SelectCurrentLocationPresenter(RestServer server) {
        super(server);
    }

    /**
     * 获取POI
     *
     * @param keyword
     * @param bround
     */
    public void getPoiList(String keyword, String bround) {
//        @Query(AppConstants.FIELD.KEY_WORD) String keyword,
//        @Query(AppConstants.FIELD.BOUNDARY) String boundary
        Map<String, Object> map =new HashMap<>();
        map.put(AppConstants.FIELD.KEY_WORD,keyword);
        map.put(AppConstants.FIELD.BOUNDARY,bround);
        invoke(mRestfull.getPoiList(map), new Callback<List<PoiList>>() {

            @Override
            public void onResponse(List<PoiList> data, Paginated paginated,Object extraData) {
                if (isnotNull()){
                    getView().onPoiSuccess(data);
                }
            }
        });
    }

    public void insertHistoryLocation(PoiList item) {
        myIChatDBHelpUtils.addEvent(new DBHandleEvent(PoiList.class, item, DBHandleEvent.OBJECT_SAVE));
    }

    public List<PoiList> selectHisLocData() {
        return myIChatDBHelpUtils.getQueryAll(PoiList.class);
    }

    public void clearHisLocData() {
        myIChatDBHelpUtils.addEvent(new DBHandleEvent(PoiList.class, null, DBHandleEvent.CLEAR_TABLE));
    }
}
